package com.sky.controller.admin;

import com.sky.dto.empployee.EmployeeDTO;
import com.sky.dto.empployee.EmployeeLoginDTO;
import com.sky.dto.empployee.EmployeePageQueryDTO;
import com.sky.dto.empployee.EmployeeUpdatePassWordDTO;
import com.sky.entity.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.Employee.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@CrossOrigin(origins = "*")   //设置跨域
@Slf4j
@Api(tags = "员工相关接口")

public class EmployeeController {


    /**
     * 登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @Autowired
    private EmployeeService employeeService;


    @PostMapping("/login")
    @ApiOperation(value = "员工登录")
    public Result login(@RequestBody EmployeeLoginDTO employeeLoginDTO)  {

        Result login = employeeService.login(employeeLoginDTO);


        return Result.success(login);

    }

    @PutMapping("/update/password")
    @ApiOperation(value = "修改登录密码")
    public Result editPassWord(@RequestBody EmployeeUpdatePassWordDTO employeeUpdatePassWordDTO){
        log.info("--------------------{}",employeeUpdatePassWordDTO);
         employeeService.EditPassWordService(employeeUpdatePassWordDTO);
         return Result.success();
    }

    /**
    退出

    @return
     */
    //TODO 以后完善
    @PostMapping("/logout")
    @ApiOperation("员工退出")
    public Result logout() {
        return Result.success();
    }

    /**
     * 新增员工
     * @param EmployeeDTO
     * @return
     */

    @PostMapping()
    @ApiOperation("新增员工")
    public Result addEmp(@RequestBody EmployeeDTO EmployeeDTO) {
       /* System.out.println("当前线程的id:"+Thread.currentThread().getId());*/
        employeeService.addEmp(EmployeeDTO);
        return Result.success();
    }




    /**
     * 分页查询
     * @param employeePageQueryDTO
     * @return
     */
    @GetMapping("/page")
     @ApiOperation("分页查询")
   public Result pageQuery( EmployeePageQueryDTO employeePageQueryDTO){
        //log.info("分页信息{}",employeePageQueryDTO);
        PageResult pageResult = employeeService.pageQueryService(employeePageQueryDTO);
        return Result.success(pageResult);
   }

       @GetMapping("/{id}")
     @ApiOperation("根据id查询员工")
     public  Result query(@PathVariable Long id){
           //log.info("id{}",id);
       Employee employee=  employeeService.selectId(id);

       return Result.success(employee);
     }

    /**
     * 修改员工
     * @param employee
     * @return
     */
     @PutMapping("/update")
     @ApiOperation("修改员工")
     public Result updateEmp(@RequestBody Employee employee){
           log.info("修改员工{}",employee);
            employeeService.update(employee);
           return Result.success();
     }

    /**
     * 启用禁用员工状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工状态")
    public Result statusEmp(@PathVariable Integer status,@RequestBody Integer id){
       // log.info("员工状态{},id{}",status,id);
       employeeService.statusEmpService(status,id);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除员工")
    public Result delete(@PathVariable Integer id){
        employeeService.deleteEmpService(id);
         log.info("id{}",id);
        return Result.success();
    }




}


